/**
 * 
 */
package com.onstar.cn.map.listener;

import android.location.Location;
import android.os.Bundle;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.onstar.cn.map.common.OLocation;

/**
 * @author Qiying Gong
 * 
 * @Created 2013-10-24
 */
public class LocationListener implements AMapLocationListener {

	private OLocationListener olistener;

	public void registerOLocationListener(OLocationListener olistener){
		this.olistener = olistener;
	}
	
	public void removeOLocationListener(){
		this.olistener = null;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.location.LocationListener#onLocationChanged(android.location.
	 * Location)
	 */
	@Override
	@Deprecated
	public void onLocationChanged(Location arg0) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.location.LocationListener#onProviderDisabled(java.lang.String)
	 */
	@Override
	public void onProviderDisabled(String arg0) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.location.LocationListener#onProviderEnabled(java.lang.String)
	 */
	@Override
	public void onProviderEnabled(String arg0) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.location.LocationListener#onStatusChanged(java.lang.String,
	 * int, android.os.Bundle)
	 */
	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.amap.api.location.AMapLocationListener#onLocationChanged(com.amap
	 * .api.location.AMapLocation)
	 */
	@Override
	public void onLocationChanged(AMapLocation location) {
		if (location != null) {
			OLocation loc = new OLocation();
			loc.setAccuracy(location.getAccuracy());
			loc.setAdcode(location.getAdCode());
			loc.setAltitude(location.getAltitude());
			loc.setBearing(location.getBearing());
			loc.setCity(location.getCity());
			loc.setCityCode(location.getCityCode());
			loc.setDistrict(location.getDistrict());
			loc.setLatitude(location.getLatitude());
			loc.setLongitude(location.getLongitude());
			loc.setProvider(location.getProvider());
			loc.setProvience(location.getProvince());
			loc.setSpeed(location.getSpeed());
			loc.setTime(location.getTime());
			
			if (this.olistener != null) {
				this.olistener.onLocationChanged(loc);
			}
			
		}
	}

}
